package com.rayboo.example.design.pattern.composite;

import java.util.ArrayList;
import java.util.List;

public class Employee {

    private String mName;
    private String mPosition;
    private int mSalary;
    private List<Employee> mSubordinates;

    public Employee(String name, String position, int salary) {
        mName = name;
        mPosition = position;
        mSalary = salary;
        mSubordinates = new ArrayList<>();
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        mName = name;
    }

    public String getPosition() {
        return mPosition;
    }

    public void setPosition(String position) {
        mPosition = position;
    }

    public int getSalary() {
        return mSalary;
    }

    public void setSalary(int salary) {
        mSalary = salary;
    }

    public void add(Employee employee) {
        mSubordinates.add(employee);
    }

    public void remove(Employee employee) {
        mSubordinates.remove(employee);
    }

    public List<Employee> getSubordinates() {
        return mSubordinates;
    }

    public String getSubordinateNames() {
        if (mSubordinates.isEmpty()) {
            return "无";
        }
        StringBuilder builder = new StringBuilder();
        for (Employee e : mSubordinates) {
            builder.append(e.getName()).append(",");
        }
        String result = builder.toString();
        return result.substring(0, result.length() - 1);
    }

    public int getSubordinateTotalSalary() {
        int result = mSalary;
        for (Employee e : mSubordinates) {
            result += e.getSubordinateTotalSalary();
        }
        return result;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "mName='" + mName + '\'' +
                ", mPosition='" + mPosition + '\'' +
                ", mSalary='" + mSalary + '\'' +
                ", mSubordinates=" + mSubordinates +
                '}';
    }
}
